<template>
	<view>
		<view class="top">
			<view class="top-font">你好！{{ nickName }}</view>
			<view class="top-avatar">
				<u--image :showLoading="true" :src="src" height="120rpx" width="120rpx" @click="click"
					shape="circle"></u--image>
			</view>
		</view>

		<view style="margin: 0 30rpx 0 30rpx;">
			<u-cell-group>
				<u-cell class="cell" icon="account" title="个人资料" isLink></u-cell>
				<u-cell icon="order" title="我的订单" @click="toOrder" isLink></u-cell>
				<u-cell icon="edit-pen" title="我的考勤" @click="toAttend" isLink></u-cell>
				<u-cell icon="calendar" title="我的课表" isLink @click="toMyCourse"></u-cell>
				<u-cell icon="man-add" title="分销中心" isLink @click="goToDistribution"></u-cell>
				<u-cell icon="setting" title="设置" isLink></u-cell>
			</u-cell-group>
		</view>
		<tabBar></tabBar>
	</view>
</template>

<script>
	import {
		selectInfoP
	} from '@/api/distribution.js'
	export default {
		data() {
			return {
				src: "",
				nickName: "",
				parentId: 0
			}
		},
		
		mounted() {
			this.getId();
		},
		onLoad() {

		},
		methods: {
			toOrder(){
				uni.navigateTo({
					url: '/pages/order-center/order-center'
				});
			},
			toAttend(){
				uni.navigateTo({
					url: '/pages/attend/attend'
				});
			},
			goToDistribution() {
				uni.navigateTo({
					url: '/pages/distributionApplication/distributionApplication'
				});
			},
			toMyCourse(){
				uni.navigateTo({
					url: '/pages/StudentSchedule/StudentSchedule'
				});
			},
			getId(){
				uni.getStorage({
				  key: 'parentId',
				  success: (res) => {  
				    this.parentId = res.data;
					this.fetchUserInfo();
				  }
				});
			},
			fetchUserInfo() {
				const params = {
					parentId: this.parentId 
				};
				selectInfoP(params).then(res => {
					if (res.code === 200) {
						this.nickName = res.data.info.parentName;
						this.src = res.data.info.parentUrl; 
					}
				}).catch(error => {
					console.error("获取信息失败:", error);
				});
				}
		}
	}
</script>

<style lang="scss">
	.top {
		width: 100%;
		height: 250rpx;
		background: #0F40F5;
		border: 1rpx solid #0d05f6;

		.top-font {
			font-size: 45rpx;
			font-family: cursive;
			font-style: italic;
			color: white;
			padding: 100rpx 55rpx 10rpx;
			float: left;
		}

		.top-avatar {
			margin-top: 65rpx;
			margin-right: 95rpx;
			float: right;
		}
	}
</style>